package megrez.job.custom;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;
import megrez.job.custom.component.Task;
import megrez.job.custom.component.ScheduledTaskManager;
import megrez.job.custom.component.ScheduledTaskContainer;

/**
 * 启动定义的任务
 *  
 * @author Lucky Yang
 * @since 2.6.9
 */
@Component
@Slf4j
public class StartTasksDataRunner implements CommandLineRunner  {
    @Autowired
    private ScheduledTaskManager scheduledTaskManager;

    @Override
    public void run(String... args) throws Exception {
        List<Task> tasks = scheduledTaskManager.startAll();
        
        log.info("Total config is {},  {} tasks started successfully ", ScheduledTaskContainer.size(), tasks.size());
        if (log.isDebugEnabled() && !tasks.isEmpty()) {
            log.debug("Started tasks list: {}", tasks);
        }        
    }
    
}
